package com.yykt.app.part8;

import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

public class Demo {







    @Test
    void testStream() {
        Stream<String> info = Stream.of("aaa", "bbb", "cccc", "ddd");
        System.out.println("========1========");
        //info.forEach(x -> System.out.println(x));
        info.forEach(System.out::println);

        System.out.println("========2========");
       // Stream<String> info2 = Stream.of("aaa", "bbb", "cccc", "ddd");
       // info.filter(x -> x.length() > 2).forEach(System.out::println);

        ArrayList<String> arrInfo = Lists.newArrayList("aaa", "bbb", "cccc", "ddd");
        System.out.println("========3========");
        arrInfo.stream().distinct().forEach(System.out::println);

        System.out.println("========4========");
        arrInfo.stream().sorted((a,b) -> a.length() - b.length()).forEach(System.out::println);

        System.out.println("========5========");
        arrInfo.stream().map(x -> x.toUpperCase()).forEach(System.out::println);

    }



    @Test
    void testStreamAdvance() {
        System.out.println("========1========");
        ArrayList<String> info = Lists.newArrayList("aaa", "bbb", "cccc", "ddd");

        Optional<String> longest = info.stream().reduce((a, b) -> a.length() > b.length() ? a : b);
        System.out.println(longest.get());

    }
}
